package linearList;

import java.util.Scanner;

public class SeqList{


    public static void main(String[] args) {

        int[] data = new int[]{66, 33, 15, 11, 78, 4, 6, 9, 6, 10, 0};

        System.out.print("打印该线性表：" + '\n');
        for (int i = 0; i < 10; i++) {
            System.out.print(data[i]);
            System.out.print("  ");
        }
        System.out.print("\n\n");

        System.out.print("查找第N个元素，请输入N：");
        Scanner input = new Scanner(System.in);
        int N = input.nextInt();
        System.out.print("第 " + N + " 个元素是 " + data[N - 1] + "\n\n");

        System.out.print("在第I个元素前，插入一个元素X。" + '\n');
        System.out.print("输入I和插入的元素X:");
        int I = input.nextInt();
        int X = input.nextInt();
        for (int i = 10; i >= I; i--) {
            data[i] = data[i - 1];
        }
        data[I - 1] = X;
        System.out.print("输出插入后的线性表：");
        for (int i = 0; i < 11; i++) {
            System.out.print(data[i]);
            System.out.print("  ");
        }
        System.out.print("\n\n");

        System.out.println("删除第II个元素。");
        System.out.print("输入II：");
        int II = input.nextInt() ;
        for ( int i = II - 1 ; i < 10 ; i ++ ) {
            data [ i ] = data [ i + 1 ] ;
        }
        System.out.print("删除后的线性表为:");
        for (int i = 0; i < 10; i++) {
            System.out.print(data[i]);
            System.out.print("  ");
        }
        System.out.print("\n\n");

        System.out.print("求所有元素之和。" + "\n");
        int sum = 0;
        for (int i = 0; i < 10; i++) {
            sum += data[i];
        }
        System.out.print("所有元素之和为：" + sum + "\n\n");

        System.out.print("打印线性表中最大的数和最小的数。" + "\n");
        int x = data[0];
        int y = data[0];
        for (int i = 0; i < 10; i++) {
            if (data[i] < x) {
                x = data[i];
            }
            if (data[i] > y) {
                y = data[i];
            }
        }
        System.out.print("线性表中的最大数为：" + y + '\n' + "线性表中的最小数为：" + x + "\n\n");

        System.out.print("逆置线性表。" + '\n');
        for (int i = 0; i < 5; i++) {
            int f = data[i];
            data[i] = data[10 - 1 - i];
            data[10 - 1 - i] = f;
        }
        System.out.print("逆置后的线性表为:");
        for (int i = 0; i < 10; i++) {
            System.out.print(data[i]);
            System.out.print("  ");
        }
        System.out.print("\n\n");

    }
}
